package com.alex.j2se.newfeature7;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 * 自动关闭try中的resource
 * Created by gaojun on 2017/11/27.
 */
public class tryWithResource {
    public static void main(String[] args) {
        try {
            System.out.println(readFirstLineFromFile("/abc"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    static String readFirstLineFromFile(String path) throws IOException {
        try (BufferedReader br = new BufferedReader(new FileReader(path))) {
            return br.readLine();
        }
    }
}
